package com.admin.action;

import com.admin.bean.KeyWord;
import com.admin.bean.KeywordType;
import com.admin.service.KeywordService;
import com.admin.service.KeywordTypeService;
import com.data.util.CheckDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 关键词管理
 *
 * @author:HingLo
 * @create 2017-09-11 16:50
 **/
@Controller
@RequestMapping("/KeyWordAction/admin/")
public class KeyWordAction {
    @Autowired
    private KeywordService KeywordService;


    @Autowired
    private KeywordTypeService keywordTypeService;

    @RequestMapping("keyword")
    public String inputKeywordAction(HttpServletRequest request) {
        List<?> list = KeywordService.findAllKeywordService();
        request.setAttribute("dataMap", list);
        return "/WEB-INF/admin/version/keyword";
    }

    /**
     * 进入到添加关键字
     *
     * @param request
     * @return
     */
    @RequestMapping("addKeyword")
    public String addkeywordAction(HttpServletRequest request, String bool) {
        List<KeywordType> list = keywordTypeService.findAllServcie();
        request.setAttribute("dataMap", list);
        if (CheckDataUtils.stringUtils(bool)) {
            request.setAttribute("bool", bool);
        }

        return "/WEB-INF/admin/version/addKeyword";
    }

    @RequestMapping("submitKeyword")
    public String submitkeywordAction(KeyWord keyWord, HttpServletRequest request) {
        boolean bool = false;
        if (keyWord != null) {
            bool = KeywordService.submitkeywordService(keyWord);
        }
        return "redirect:addKeyword?bool=" + String.valueOf(bool);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping("delKeyword")
    @ResponseBody
    public String delKeywordAction(String id) {
        return String.valueOf(KeywordService.delKeywordService(id));
    }

}
